# $Id$
# Maintainer : Felix Yan <felixonmars@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgbase=pyopenssl
pkgname=('python-pyopenssl' 'python2-pyopenssl')
pkgver=17.3.0
pkgrel=1
arch=('any')
url="http://pypi.python.org/pypi/pyOpenSSL"
license=('LGPL2.1')
makedepends=('openssl' 'python-setuptools' 'python2-setuptools' 'python-cryptography'
             'python2-cryptography')
checkdepends=('python-pytest-runner' 'python2-pytest-runner' 'python-pretend' 'python2-pretend'
              'python-flaky' 'python2-flaky')
source=("https://pypi.io/packages/source/p/pyOpenSSL/pyOpenSSL-$pkgver.tar.gz")
sha512sums=('2b58a652b8d6e2adadbc620a6b3411cd44169940ef1839fd3365cd343ebe1e630ddbb580d8d4dc79e738e0b4f91db0bdbbaecf18aea74204499c737eebb3fae8')

prepare() {
  cp -a pyOpenSSL-$pkgver{,-py2}

  export LC_CTYPE=en_US.UTF-8
}

build () {
  cd "$srcdir"/pyOpenSSL-$pkgver
  python setup.py build

  cd "$srcdir"/pyOpenSSL-$pkgver-py2
  python2 setup.py build
}

check () {
  (
    cd "$srcdir"/pyOpenSSL-$pkgver
    python setup.py pytest

    cd "$srcdir"/pyOpenSSL-$pkgver-py2
    python2 setup.py pytest
  ) || warning "Tests failed due to missing SSLv3_METHOD"
}

package_python-pyopenssl(){
  pkgdesc="Python3 wrapper module around the OpenSSL library"
  depends=('openssl' 'python-six' 'python-cryptography')
  replaces=('pyopenssl')
  provides=('pyopenssl')
  conflicts=('pyopenssl')

  cd "$srcdir"/pyOpenSSL-$pkgver
  python setup.py install --root="$pkgdir" --optimize=1
}

package_python2-pyopenssl(){
  pkgdesc="Python2 wrapper module around the OpenSSL library"
  depends=('openssl' 'python2-six' 'python2-cryptography')

  cd "$srcdir"/pyOpenSSL-$pkgver-py2
  python2 setup.py install --root="$pkgdir" --optimize=1
}
